
<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:oxf="http://www.orbeon.com/oxf/processors">
    <p:processor name="oxf:request">
        <p:input name="config">
            <config >
                <include>/request/parameters</include>
                <include>/request/headers</include>
            </config>
        </p:input>
        <p:output name="data" id="request"/>
    </p:processor>
    <p:processor name="oxf:xslt">
        <p:input name="data" href="#request#xpointer(/request/headers/header[name='x-forward-url'])"/>
        <p:output name="data" id="config_url"/>
        <p:input name="config">
            <config xsl:version="2.0">
                <url>
                    <xsl:value-of select="/header/value"/>
                </url>
                <content-type>application/xml</content-type>
            </config>
        </p:input>
    </p:processor>

    <p:processor name="oxf:url-generator">
        <p:input name="config" href="#config_url"/>
        <p:output name="data" id="request-doc"/>
    </p:processor>

    <p:choose href="#request">
        <p:when test="exists(/request/parameters/parameter[name='xquery'])">
            <p:processor name="oxf:xslt">
                <p:input name="data" href="#request#xpointer(/request/parameters/parameter[name='xquery'])"/>
                <p:input name="config">
                    <document xsl:version="2.0" xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                        <xsl:value-of select="/parameter/value"/>
                    </document>
                </p:input>
                <p:output name="data" id="xquery"/>
            </p:processor>
            <p:processor name="oxf:xquery">
                <p:input name="config" href="#xquery"/>
                <p:input name="data" href="#request-doc"/>
                <p:output name="data" id="transformed"/>
            </p:processor>
        </p:when>
        <p:when test="exists(/request/parameters/parameter[name='xslt'])">
            <p:processor name="oxf:xslt">
                <p:input name="data" href="#request"/>
                <p:output name="data" id="xslurl"/>
                <p:input name="config">
                    <config xsl:version="2.0">
                        <url>
                            <xsl:text>/widgets/</xsl:text>
                            <xsl:value-of select="/request/parameters/parameter[name='id']/value"/>
                            <xsl:if test="not(starts-with(/request/parameters/parameter[name='xslt']/value, '/'))">/</xsl:if>
                            <xsl:value-of select="/request/parameters/parameter[name='xslt']/value"/>
                        </url>
                        <content-type>application/xml</content-type>
                    </config>
                    
                </p:input>
            </p:processor>
            <p:processor name="oxf:url-generator">
                <p:input name="config" href="#xslurl"/>
                <p:output name="data" id="xsl"/>
            </p:processor>
            <p:processor name="oxf:xslt">
                <p:input name="data" href="#request-doc"/>
                <p:input name="config" href="#xsl"/>
                <p:output name="data" id="transformed"/>
            </p:processor>
        </p:when>
    </p:choose>

    <p:processor name="oxf:xml-converter">
        <p:input name="config">
            <config>
                <content-type>text/xml</content-type>
                <encoding>utf-8</encoding>
            </config>
        </p:input>
        <p:input name="data" href="#transformed"/>
        <p:output name="data" id="xml-doc"/>
    </p:processor>

    <p:processor name="oxf:http-serializer">
        <p:input name="config">
            <config>
                <content-type>text/xml</content-type>
            </config>
        </p:input>
        <p:input name="data" href="#xml-doc"/>
    </p:processor>

</p:config>